package org.jason.minio.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jason.minio.service.PictureService;
import org.jason.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/material")
@Api(tags = "素材管理模块", value = "MaterialController")
public class MaterialController {

    @Autowired
    private PictureService pictureService;

    @ApiOperation("上传素材")
    @SaCheckLogin
    @PostMapping("/upload")
    private ResponseResult uploadMaterial(@RequestParam("file") MultipartFile file) {
        return pictureService.uploadMaterial(file);
    }

    //获取用户上传的素材
    @ApiOperation("获取用户上传的素材")
    @SaCheckLogin
    @GetMapping("/list")
    public ResponseResult getMaterials() {
        return pictureService.getMaterials();
    }

    //根据文件名删除素材
    @ApiOperation("根据文件名删除素材,格式:userId/filename.xxx")
    @SaCheckLogin
    @DeleteMapping("/delete")
    public ResponseResult deleteMaterial(@RequestBody String filename) {
        return pictureService.deleteMaterial(filename);
    }
}
